package com.hgyc.mom.system.controller;

import com.hgyc.mom.common.vo.Result;
import com.hgyc.mom.system.entity.SysOrg;
import com.hgyc.mom.system.service.SysOrgService;
import com.hgyc.mom.system.vo.OrgVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 组织结构 前端控制器
 * </p>
 *
 * @author fwj
 * @since 2025-02-20
 */
@RestController
@RequestMapping("/sys/org")
public class SysOrgController {

    @Autowired
    private SysOrgService sysOrgService;

    @RequestMapping(value = "/all", method = RequestMethod.GET)
    public Result<List<OrgVO>> getAll() {
        List<OrgVO> roleMenus = sysOrgService.all();
        return Result.success(roleMenus);
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @Operation(summary = "根据ID查询组织架构", description = "根据ID查询组织架构")
    public Result<SysOrg> queryById(@PathVariable("id") Long id) {
        SysOrg sysOrg = sysOrgService.getById(id);
        return Result.success(sysOrg);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @Operation(summary = "新增组织架构", description = "新增组织架构")
    public Result<?> add(
            @Parameter(description = "组织架构") @RequestBody SysOrg sysOrg) {
        sysOrgService.save(sysOrg);
        return Result.success("保存成功");
    }

    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    @Operation(summary = "更新组织架构", description = "更新组织架构")
    public Result<?> updateUserinfo(
            @Parameter(description = "系统用户") @RequestBody SysOrg sysOrg) {
        sysOrgService.updateById(sysOrg);
        return Result.success("更新成功");
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    @Operation(summary = "根据ID删除组织", description = "根据ID删除组织")
    public Result<?> deleteById(@PathVariable("id") Long id) {
        sysOrgService.removeById(id);
        return Result.success("删除成功");
    }

}
